﻿CREATE PROCEDURE [dbo].[kp_KiemTraSoCmnd]
	@So_Cmnd nvarchar(12),
	@KetQua int output,
	@ThongBao nvarchar(256) Output
	
AS
begin
	Declare @Ma_HsCn nvarchar(10),@Count int,@Ten_HoKd nvarchar(127)
	Select @Ma_HsCn=Ma_HsCn from tblHoSoCn where So_Cmnd=@So_Cmnd
	if @Ma_HsCn is null
	BEGIN
		set @KetQua=1
		set @ThongBao=''
	END
	ELSE
	BEGIN
		SELECT @Ten_HoKd=Ten_HoKd from (Select top 1 Ten_HoKd from tblDangKyKd 
				WHERE Ma_HsCn=@Ma_HsCn
					AND Ht=1
					AND Ma_LoaiHs IN('DK','CL','TN')) T
		if @Ten_HoKd IS NOT NULL
		BEGIN			
			set @KetQua=0
			Set @ThongBao=N'Cá nhân đang làm chủ hộ kinh doanh '+@Ten_HoKd
		END
		
	END
RETURN 0;
end
